﻿Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Data.OleDb

Public Class frmLogin

    Dim con As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim reader As OleDbDataReader

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=|DataDirectory|\db.accdb"
        cmd.Connection = con
    End Sub


    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim str As String = "select Passwort from Mitarbeiter where Benutzername = '" & txbUsername.Text & "'"
        con.Open()
        cmd.CommandText = str
        reader = cmd.ExecuteReader()
        If txbUsername.Text <> "" Or txbPasswort.Text <> "" Then
            Do While reader.Read()
                Dim answer As String = reader("Passwort")
                If answer = txbPasswort.Text Then
                    Dim loggedin As Projekt = Projekt.GetObject()
                    loggedin.mitarbeiter = txbUsername.Text

                    frmmain.Show()
                    Me.Hide()
                Else
                    lblError.Text = "Eingabe falsch"
                End If
            Loop
        Else
            lblError.Text = "Eingaben fehlen"
        End If
        con.Close()
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub


End Class
